<link rel="stylesheet" href="css/combobox/Selectyze.jquery.css" type="text/css" />

<div class="product">
	<?php 
	// get category id
	@$cat_id=$_REQUEST["cat_id"];
	?>
	<?php
		if($cat_id<>"")
		{
			echo "<div class='title_product'>Nos Produits</div>";
		}
		else
		{
			echo "<div class='title_product'>Nos Catégories</div>";
		}
    ?>
    <div class="search">
        <form method="post" id="frmsearchCat" action="index.php?page=product" >
        	<?php
				$sql="SELECT * FROM tbl_category WHERE public=1  ORDER BY  orders ASC";
				$result=query($sql);
			?>
            	<select name="cbocategory" class="selectyze2" onchange="frmSubmit('frmsearchCat','index.php?page=product');">
                	<!--<option value="">sélectionner la catégorie</option>-->
            <?php	
				while($row=mysql_fetch_object($result))
				{
			?>	
					<option value="<?php echo $row->cat_id;?>"><?php echo $row->cat_name;?></option>
			<?php
				}
            ?>
            	</select>
		</form>
	<!--<script type="text/javascript" src="js/combobox/jquery.js"></script>-->
	<script type="text/javascript" src="js/combobox/Selectyze.jquery.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$('.selectyze1').Selectyze({
				theme : 'skype'
			});
			
			$('.selectyze2').Selectyze({
				theme : 'mac'
			});
			
			$('.selectyze3').Selectyze({
				theme : 'grey'
			});	
			
			$('.selectyze4').Selectyze({
				theme : 'firefox'
			});
			
			$('.selectyze5').Selectyze({
				theme : 'css3'
			});
			
		});
	</script>
    </div>
    <div style="clear:both;"></div>
    <div class="wraper_cat">
    <?php
		//get from cbocategory
		@$cbocategory=$_REQUEST["cbocategory"];
		//@$cbocategory=$_REQUEST["cbocategory"];
		
		if($cat_id <>"" || $cbocategory<>"")
		{
	?>
    	<?php
				//include function from cls_pag
				include('includes/cls_pagination.php');
				// get product by category
				$sql="SELECT * FROM tbl_product WHERE cat_id='$cat_id' OR cat_id='$cbocategory' ";
				$result=query($sql);
				$Num_Rows = mysql_num_rows($result);
				$Per_Page = 5;   // Per Page
				@$Page = $_GET["Page"];
				if(!@$Page)
									{
										$Page=1;
									}
									
									$Prev_Page = $Page-1;
									$Next_Page = $Page+1;
									
									$Page_Start = (($Per_Page*$Page)-$Per_Page);
									if($Num_Rows<=$Per_Page)
									{
										$Num_Pages =1;
									}
									else if(($Num_Rows % $Per_Page)==0)
									{
										$Num_Pages =($Num_Rows/$Per_Page) ;
									}
									else
									{
										$Num_Pages =($Num_Rows/$Per_Page)+1;
										$Num_Pages = (int)$Num_Pages;
									}
									 
									$sql .=" ORDER BY pro_id DESC  LIMIT $Page_Start , $Per_Page";
									$result  = mysql_query($sql);
        ?>
        <?php
				while($row=mysql_fetch_object($result))
				{
        ?>
            	<div class="list_product">
                    <div class="list_product_img"><a href="index.php?page=detail&pro_id=<?php echo $row->pro_id;?>"><img src="admin/product/<?php echo $row->photo;?>"  height="190" width="150"/></a></div>
                    <div class="list_product_name"><h3><?php echo $row->pro_name;?></h3>
                        <div class="list_product_des">
                            <p><?php $sms=substr($row->pro_description,0,220);   echo stripcslashes($sms)."...";?></p>
                        </div>
                        <div class="list_product_detail"><a href="index.php?page=detail&pro_id=<?php echo $row->pro_id;?>"><img src="images/btn-detail.gif" /></a><a href="index.php?page=contact&pro_name=<?php echo $row->pro_name;?>"><img src="images/btn-contact.gif" /></a></div>
                    </div>
               </div>
        <?php
			    }
				if($Num_Rows>5)
				{
					echo "<div id='record_paginate_act'>";
									
						$pages = new Paginator;
						$pages->items_total = $Num_Rows;
						$pages->mid_range = 5;
						$pages->current_page = $Page;
						$pages->default_ipp = $Per_Page;
						$pages->url_next ="index.php?page=product&cat_id=$cat_id&cbocategory=$cbocategory&QueryString=value&Page=";
						$pages->paginate();
											
						echo $pages->display_pages();
										
					echo " </div>" ;
			    }//end check number of product 
         ?>
    <?php
		}
		else
		{
	?>
    		<?php
				$sql="SELECT * FROM tbl_category WHERE public=1  ORDER BY  orders ASC";
				$result=query($sql);
			?>
            	
            <?php
				while($row=mysql_fetch_object($result))
				{
            ?>
        			<div class="list_cat">
                       <div class="list_cat_img"> <a href="index.php?page=product&cat_id=<?php echo $row->cat_id;?>"><img src="admin/category/<?php echo $row->photo;?>" height="190" width="150"/></a></div>
                        <div class="list_cat_title"><a href="index.php?page=product&cat_id=<?php echo $row->cat_id;?>"><?php echo $row->cat_name;?></a></div>
                    </div>
        
        	<?php
				}
            ?>
    <?php
		}
    ?>
    </div><!-- enc wraper_cat-->
</div><!-- enc product-->
